<!--
 * @由于个人水平有限, 难免有些错误, 还请指点:  
 * @Author: cpu_code
 * @Date: 2020-10-15 18:56:21
 * @LastEditTime: 2020-10-16 21:46:19
 * @FilePath: \web\javascript\js_array\js_array.html
 * @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
 * @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
 * @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
 * @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
-->
<!DOCTYPE html>
<html lang="ch">
    <head>
        <meta charset="UTF-8">
        <title>Array对象</title>
        <script>
            /*
                Array:数组对象
                    1. 创建：
                1. var arr = new Array(元素列表);
                    2. var arr = new Array(默认长度);
                    3. var arr = [元素列表];
                3. 属性
                    length:数组的长度
                4. 特点：
                    1. JS中，数组元素的类型可变的。
                    2. JS中，数组长度可变的。
            */
            //1.创建方式1
            var arr1 = new Array(1,2,3);
            var arr2 = new Array(5);
            var arr3 = [1,2,3,4];
            var arr4 = new Array();

            document.write(arr1 +"<br>");
            document.write(arr2 +"<br>");
            document.write(arr3 +"<br>");
            document.write(arr4 +"<br>");

            var arr = [1,"cpu",true];
            document.write("arr = " + arr + "<br>");

            document.write("arr[0] = " + arr[0] + "<br>");
            document.write("arr[1] = " + arr[1] + "<br>");
            document.write("arr[2] = " + arr[2] + "<br>");

            document.write("arr[10] = " + arr[10] +"<br>");
            arr[10] = "cpucode";
            document.write("arr[10] = " + arr[10] +"<br>");
            document.write("arr[9] = " + arr[9] +"<br>");

            document.write("arr.length = " + arr.length + "<br>");
            // join(参数):将数组中的元素按照指定的分隔符拼接为字符串
            document.write(arr.join("---") + "<br>");
            // push()	向数组的末尾添加一个或更多元素，并返回新的长度
            arr.push(11);
            document.write(arr.join("---") + "<br>");
        </script>
    </head>
</html>